//  GSCategories
//
//  Created by Hgq on 16/3/2.
//  Copyright © 2016年 halis co.,Ltd. All rights reserved.
//
#import "UIColor+Additions.h"

typedef unsigned int ADDColorType;

#define ADD_RED_MASK        0xFF0000
#define ADD_GREEN_MASK      0xFF00
#define ADD_BLUE_MASK       0xFF

#define ADD_RED_SHIFT       16
#define ADD_GREEN_SHIFT     8
#define ADD_BLUE_SHIFT      0

#define ADD_COLOR_SIZE      255.0

#define GREEN_COLOR_HEX @"009d85"

#define DEFAULT_COLOR_HEX @"3c3c3c"

@implementation UIColor (Additions)


+ (UIColor *)vDividingLineColor{
    return [self colorWithHexString:@"#F0F0F0"];
}
+ (UIColor *)vSplitBarColor{
    return [self colorWithHexString:@"#FAFAFA"];
}

+ (UIColor *)vListDateColor{
    return [UIColor colorWithHexString:@"#D3D3D3"];
}









/**
 *  用色命名方案2.0
 */

+ (UIColor *)mainTitleColor
{
    return [self c2Color];
}

+ (UIColor *)themeColor
{
    return [self c1Color];
}

+ (UIColor *)themeTitleColor
{
    return [self c3Color];
}

+ (UIColor *)subTitleColor
{
    return [self c4Color];
}

+ (UIColor *)disableTitleColor
{
    return [self c5Color];
}

+ (UIColor *)separatorColor
{
    return [self c7Color];
}

+ (UIColor *)themeBackgroundColor
{
    return [self c8Color];
}


+ (UIColor *)countCodeColor
{
    return [self add_colorWithRGBHexString:@"167EFC"];
}

/* ==============05.28用色定稿方案===================*/

+ (UIColor *)c1Color
{
    return [self add_colorWithRGBHexString:@"2F62D3"];
}


+ (UIColor *)c20Color
{
    return [self add_colorWithRGBHexString:@"F74B6D"];
}

+ (UIColor *)c06Color
{
    return [self add_colorWithRGBHexString:@"46619C"];
}

+ (UIColor *)c02Color
{
    return [self add_colorWithRGBHexString:@"8CC126"];
}

+ (UIColor *)c07Color
{
    return [self add_colorWithRGBHexString:@"F4FAE5"];
}

+ (UIColor *)c21Color
{
    return [self add_colorWithRGBHexString:@"E64340"];
}


+ (UIColor *)c22Color
{
    return [self add_colorWithRGBHexString:@"ED8218"];
}

+ (UIColor *)c23Color
{
    return [self add_colorWithRGBHexString:@"FEBD0B"];
}

+ (UIColor *)c25Color
{
    return [self add_colorWithRGBHexString:@"FEF8F2"];
}

+ (UIColor *)c3Color
{
    return [self add_colorWithRGBHexString:@"333333"];
}

+ (UIColor *)c6Color
{
    return [self add_colorWithRGBHexString:@"666666"];
}
+ (UIColor *)c9Color
{
    return [self add_colorWithRGBHexString:@"999999"];
    
}

+ (UIColor *)c7Color
{
    return [self add_colorWithRGBHexString:@"EDEDED"];
}


+ (UIColor *)c8Color
{
    return [self add_colorWithRGBHexString:@"BD123D"];
}

+ (UIColor *)c60Color
{
    return [self add_colorWithRGBHexString:@"C1C1C1"];
    
}


+ (UIColor *)grayBtnTitleColor
{
     return [self add_colorWithRGBHexString:@"CDCDCD"];;
}

+ (UIColor *)darkTitleColor
{
    return [self add_colorWithRGBHexString:@"111111"];
}

+ (UIColor *)proctolColor
{
    return [self add_colorWithRGBHexString:@"167EFB"];
}

/* ==============05.28用色定稿方案===================*/








+ (UIColor *)c2Color
{
    return [self add_colorWithRGBHexString:@"010101"];
}

+ (UIColor *)c01Color
{
    return [self add_colorWithRGBHexString:@"243C70"];
}



+ (UIColor *)c03Color
{
    return [self add_colorWithRGBHexString:@"E64340"];
}

+ (UIColor *)c04Color
{
    return [self add_colorWithRGBHexString:@"EA882B"];
}

+ (UIColor *)c05Color
{
    return [self add_colorWithRGBHexString:@"FBBC2F"];
}


+ (UIColor *)c4Color
{
    return [self add_colorWithRGBHexString:@"666666"];
}

+ (UIColor *)c5Color
{
    return [self add_colorWithRGBHexString:@"C6C6C6"];
}



+ (UIColor *)c24Color
{
    return [self add_colorWithRGBHexString:@"F8F9FC"];
}


/**
 *  基础配色方案
 */
+ (UIColor*)add_colorWithRGBHexString:(NSString*)rgbStrValue
{
    ADDColorType rgbHexValue;
    
    NSScanner* scanner = [NSScanner scannerWithString:rgbStrValue];
    BOOL successful = [scanner scanHexInt:&rgbHexValue];
    
    if (!successful)
        return nil;
    
    return [self add_colorWithRGBHexValue:rgbHexValue];
}

+ (UIColor*)add_colorWithRGBHexValue:(ADDColorType)rgbValue
{
    return [UIColor colorWithRed:((CGFloat)((rgbValue & ADD_RED_MASK) >> ADD_RED_SHIFT))/ADD_COLOR_SIZE
                           green:((CGFloat)((rgbValue & ADD_GREEN_MASK) >> ADD_GREEN_SHIFT))/ADD_COLOR_SIZE
                            blue:((CGFloat)((rgbValue & ADD_BLUE_MASK) >> ADD_BLUE_SHIFT))/ADD_COLOR_SIZE
                           alpha:1.0];
}

+ (UIColor *)colorWithHexString:(NSString *)hexString;
{
    NSString *cString = [[hexString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    if ([cString length] < 6) {
        return [UIColor whiteColor];
    }
    
    if ([cString hasPrefix:@"#"]) {
        cString = [cString substringFromIndex:1];
    }
    
    if ([cString length] != 6) {
        return [UIColor whiteColor];
    }
    
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float)r / 255.0f)
                           green:((float)g / 255.0f)
                            blue:((float)b / 255.0f)
                           alpha:1.0f];
}

+ (UIColor *)colorWithHexString:(NSString *)stringToConvert alpha:(CGFloat)alpha {
    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    
    if ([cString length] < 6)
        return [UIColor whiteColor];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor whiteColor];
    
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:alpha];
}



+ (UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size
{
    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return theImage;
}

+ (UIImage *)createImageWithColor:(UIColor *)color
{
    return [self createImageWithColor:color size:CGSizeMake(1.0, 1.0)];
}

- (BOOL)isEqualToColor:(UIColor *)color
{
    return (CGColorEqualToColor(self.CGColor,color.CGColor));
}


@end
